#!/bin/sh

# 09.11.2006 Volker Quetschke
# Check that TMD honors if .SETDIR is used (with drive letters on cygwin)
# (issue 69821).

: ${DMAKEPROG:=dmake}
file1="mfile1.mk"
tmpfiles="$file1"

trap '{ echo "trapped signal - removing temporary files" ; rm -rf $tmpfiles ; }' 1 2 3 15

# Remove files from prior failed run
rm -rf $tmpfiles

# Remember to quote variables in generated makefiles( $ -> \$ ).
# Testcase 1
cat > $file1 <<EOT
SHELL*:=/bin/sh 
SHELLFLAGS*:=-ce

.IMPORT .IGNORE : TEMP
.IF "\$(TEMP)"==""
TEMP:=/tmp
.ENDIF


# Test if .SETDIR works with drive letters
.IF "\$(subst,Cygwin, \$(shell @uname))"!="\$(shell @uname)"
SDIR:=\$(shell @+cygpath -d "\$(TEMP)")
.ELSE
SDIR:=\$(TEMP)
.ENDIF

# Make TEMP the target directory, cd to TMD should go back to
# the original directory
all ".SETDIR=\$(SDIR)" :
	@+cd \$(TMD); pwd

EOT


output1=`eval ${DMAKEPROG} -r -f $file1`
result1=$?

if test "$output1" != "`pwd`"; then
  echo "Test 1: Wrong result: ${output1}"
  result1=1
else
  echo "Test 1: OK"
fi

if test $result1 -eq 0; then
  echo "Success - Cleaning up"
  rm -rf $tmpfiles
exit
  result=0
else
  echo "Failure!"
  result=1
fi
exit $result 
